/* Sokoban
 * HIT3243
 * Authors: Mike Blackney, Ben Ingarfield, Kurniawan
 */

#include <fstream>
#include "help.h"
#include "registrar.h"

// Here are the GUI magic numbers:

#define IDC_OKAY			8

// The options file name:
#define OPTIONS_FILE L"sokoban_options.txt"

Help* const Help::Instance() {
	static Help instance;
	return &instance;
}

HRESULT Help::Load() {
	HRESULT hr;

	V_RETURN(GameStateGUI::Load());

	// Get the title sprite:
	V_RETURN(title.CreateFromFile(L"SokobanAbout.png"));

	// Add the GUI items
	V_RETURN(dialog.AddButton(IDC_OKAY, L"Okay", 550, 550, 100, 25, 'O', true));

	dxf::DXFSetClear(true);
	//dxf::DXFSetClearColor(BLACK);
	return S_OK;
}

void Help::Unload() {
	title.Unload( );

	GameStateGUI::Unload();
	
}

void Help::Update(double fTime, float fElapsedTime) {
}

void Help::Render2D(double fTime, float fElapsedTime) {
	// Render the "Options" heading sprite:
	title.Render2D( );
}

void Help::Resize(const D3DSURFACE_DESC* d) {
	// Put the dialog back in the corner (this step probably unnecessary)
	dialog.SetLocation( 0, 0 );

	// Make its size match the size of the screen
	dialog.SetSize( d->Width, d->Height );
}

bool Help::MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
	// Pass windows messages to the resource manager and all the gui objects
	if (GameStateGUI::MsgProc(hWnd, uMsg, wParam, lParam)) return true;

	// Pressing ESC during score entry will take you to the Title:
	if (uMsg == WM_KEYDOWN && wParam == VK_ESCAPE) {
		dxf::DXFChangeState(Registrar::kTitle);
		return true;
	}

	return false;	// let the engine handle everything else.
}

void Help::OnGUIEvent( UINT nEvent, int nControlID, CDXUTControl* pControl, void* pUserContext ) {
    switch( nControlID ) {

	case IDC_OKAY: 
		bUpdateOptions = true;
		dxf::DXFChangeState(Registrar::kTitle);
		break;

	default:
		assert(false);
		break;
	}
}